package _07_串;

import java.util.*;

public class _299_猜数字游戏 {

    public static void main(String[] args) {

        _299_猜数字游戏 v = new _299_猜数字游戏();

        String secret = "1807";
        String guess  = "7810";
        System.out.println(v.getHint(secret, guess));

    }

    public String getHint(String secret, String guess) {
        int bullsCount = 0;
        int rowSCount = 0;
        int len = secret.length();
        int[] secretAry = new int[10];
        int[] guessAry = new int[10];
        for (int i = 0; i < len; i++) {
            char secretChar = secret.charAt(i);
            char guessChar = guess.charAt(i);
            if (secretChar == guessChar) {
                bullsCount++;
            } else {
                secretAry[secretChar - '0']++;
                guessAry[guessChar - '0']++;
            }
        }

        for (int i = 0; i < 10; i++) {
            rowSCount += Math.min(secretAry[i], guessAry[i]);
        }
        return bullsCount + "A" + rowSCount + "B";
    }

}
